home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Subject: Re: Splitting String ?
- X-Nntp-Posting-Host: foley.ripco.com
- Message-ID: <DL3u9M.9xt@rci.ripco.com>
- Sender: usenet@rci.ripco.com (Net News Admin)
- Organization: Ripco Internet BBS Chicago
- Date: Sat, 13 Jan 1996 05:36:58 GMT
- X-Ident-Sender: mambuhl
-
- hakola@cadmail.hut.fi (Petri Hakola) in
- <HAKOLA.96Jan12151128@jung.hut.fi> asks:
-
-
- > Have I missed something (again:) or why doesn't this code
- > work? I should split dos-a-like-filename and add new postfix
- > instead of old one (i.e. DATA.TXT --> DATA.UPD It seems to
- > work correctly if the filename has an old postfix, but if
- > there isn't one start won't return what it should.
-
- > - P -
-
- I may have missed something here, too. Your code [at EOM] seems to work
- for me. However, it looks like you do a lot of extra work that may be
- obscuring the problem. Why not start with a replacement for newname
- that looks like the following and see if it satisfies your needs:
-
- char *newname(char *s)
- {
-
- char *dot;
- dot = strchr(s, '.');
- if (dot)
- *dot = '\0';
- strcat(s, ".UPD");
- return s;
- }
-
-
- [ === Petri's code === ]
- >---Clip---
- >#include <stdio.h>
- >#include <string.h>
-
- >char *newname(char *s) {
-
- > char *dot;
- > char *start;
- > char end[5];
-
- > strcpy(end,".UPD");
- > start = s;
- > dot = strchr(s,'.');
- > if( dot == NULL) {
- > start[strlen(start)] = '\0';
- > dot = end;
- > } else {
- > *dot = '\0';
- > dot++;
- > dot = end;
- > }
- > strcat(start, dot);
- > return start;
- >}
-
- >main() {
- > printf("%s\n",newname("LONGNAME.TXT"));
- > printf("%s\n",newname("NOEND"));
- >}
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-